{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cjMQsd_m2lYM"
      },
      "source": [
        "##### Copyright 2025 Google LLC."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "yVDX4Kwb2jYl"
      },
      "outputs": [],
      "source": [
        "# @title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
        "# you may not use this file except in compliance with the License.\n",
        "# You may obtain a copy of the License at\n",
        "#\n",
        "# https://www.apache.org/licenses/LICENSE-2.0\n",
        "#\n",
        "# Unless required by applicable law or agreed to in writing, software\n",
        "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
        "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
        "# See the License for the specific language governing permissions and\n",
        "# limitations under the License."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "dUZly7nXqxfD"
      },
      "source": [
        "# Function Calling Router for Gemma-3: Implement and Monitor Agentic RAG workflow",
        "\n",
        "<table align=\"left\">\n",
        "  <td>\n",
        "    <a target=\"_blank\" href=\"https://colab.research.google.com/github/google-gemini/gemma-cookbook/blob/main/Gemma/[Gemma_3]Function_Calling_Routing_and_Monitoring_using_Gemma_Google_Genai.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
        "  </td>\n",
        "</table>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "oi9yFtuO8-o9"
      },
      "source": [
        "## Overview\n",
        "\n",
        "**Gemma-3 natively doesn’t support Function calling at Inference** with Ollama or HuggingFace. Gemma-3 models pulled from the official Ollama registry do not advertise dedicated tool/function calling tags, and Ollama will return an error if requesting native tool support through direct means.​\n",
        "\n",
        "### Our approach:\n",
        "\n",
        "- Perform function calling by prompt engineering using delimiters hardcoded rather than by native tokens or system templates.\n",
        "- Structured outputs and Agentic workflows are possible, but developers need to provide clear function definitions and parse model outputs for tool invocation details.\n",
        "\n",
        "### Author Details\n",
        "- **Author**: Tarun Jain\n",
        "- **GitHub**: [@lucifertrj](https://github.com/lucifertrj)  \n",
        "- **LinkedIn**: [@Tarun R Jain](http://linkedin.com/in/jaintarun75)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "CwIyIKDI9QuB"
      },
      "source": [
        "## Installation"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "JjICXvOCPxBx"
      },
      "outputs": [],
      "source": [
        "!pip install langgraph langchain-community\n",
        "!pip install langchain-qdrant fastembed\n",
        "!pip install pypdfium2\n",
        "!pip install duckduckgo-search ddgs # custom function\n",
        "!pip install opik # monitoring and tracing\n",
        "!pip install langchain-google-genai  # gemma-3-27b-it"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "HaNgkN0G88lv"
      },
      "source": [
        "## Document processing"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {
        "id": "lSB_y8Jo7oL6"
      },
      "outputs": [],
      "source": [
        "# data extraction and chunking\n",
        "# my data is inside: a folder\n",
        "# single file pdf\n",
        "from langchain_community.document_loaders import FileSystemBlobLoader\n",
        "from langchain_community.document_loaders.generic import GenericLoader\n",
        "from langchain_community.document_loaders.parsers import PyPDFium2Parser\n",
        "\n",
        "# embedding model\n",
        "from langchain_community.embeddings import FastEmbedEmbeddings # sparse and dense (hybrid search)\n",
        "\n",
        "# vector database dependency\n",
        "from langchain_qdrant import FastEmbedSparse, QdrantVectorStore, RetrievalMode # hybrid\n",
        "from qdrant_client import QdrantClient, models"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ywW8aIWo-RP6"
      },
      "source": [
        "### Data loading- Raw data extraction\n",
        "\n",
        "With reference to this PDF Parser comparison paper, PDFium performs well on Financial documents. [arxiv.org/abs/2410.09871](https://arxiv.org/abs/2410.09871)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {
        "id": "hFObHjZ_9s5X"
      },
      "outputs": [],
      "source": [
        "loader = GenericLoader(\n",
        "    blob_loader=FileSystemBlobLoader(\n",
        "        path=\"data\",\n",
        "        glob=\"*.pdf\",\n",
        "    ),\n",
        "    blob_parser=PyPDFium2Parser(),\n",
        ")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "metadata": {
        "id": "VJCpW6zm93iV"
      },
      "outputs": [],
      "source": [
        "docs = loader.load()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {
        "id": "jAbT6rjk949A"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "3"
            ]
          },
          "execution_count": 5,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "len(docs)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "metadata": {
        "id": "p7RVK7ZO96Tb"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "{'producer': 'Microsoft® Word LTSC',\n",
              " 'creator': 'Microsoft® Word LTSC',\n",
              " 'creationdate': '2025-07-23T13:00:52+05:30',\n",
              " 'title': '',\n",
              " 'author': 'aDMIN',\n",
              " 'subject': '',\n",
              " 'keywords': '',\n",
              " 'moddate': '2025-07-23T13:00:52+05:30',\n",
              " 'source': 'data/23AI5PCOTM-OTML.pdf',\n",
              " 'total_pages': 3,\n",
              " 'page': 0}"
            ]
          },
          "execution_count": 6,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "docs[0].metadata"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "uaV-5KVC-Ny0"
      },
      "source": [
        "### Initialize Dense and Sparse Embeddings"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "EsLws9PD99kS"
      },
      "outputs": [],
      "source": [
        "dense_embeddings = FastEmbedEmbeddings(model_name=\"jinaai/jina-embeddings-v2-base-en\")\n",
        "sparse_embeddings = FastEmbedSparse(model_name=\"Qdrant/bm25\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cTIXP34a-Uqa"
      },
      "source": [
        "### Initialize your Vector database and config the collection- Hybrid Search"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {
        "id": "olMufkgo-M-1"
      },
      "outputs": [],
      "source": [
        "collection_name = \"agenticrag\"\n",
        "client = QdrantClient(path=\"/tmp/db\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {
        "id": "FfbeWW52-eIt"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "True"
            ]
          },
          "execution_count": 9,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "client.create_collection(\n",
        "    collection_name = collection_name,\n",
        "    vectors_config = {\n",
        "        \"dense1\": models.VectorParams(size = 768,\n",
        "                                     distance = models.Distance.COSINE\n",
        "                                     )},\n",
        "    sparse_vectors_config={\n",
        "        \"sparse1\": models.SparseVectorParams(\n",
        "            index = models.SparseIndexParams(on_disk=False),\n",
        "            modifier = models.Modifier.IDF,\n",
        "        )\n",
        "    },\n",
        ")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xJ4aVM4e_QCe"
      },
      "source": [
        "### Index your data"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {
        "id": "n9cAx-Ni-6Gi"
      },
      "outputs": [],
      "source": [
        "db = QdrantVectorStore(\n",
        "    client = client,\n",
        "    collection_name = collection_name,\n",
        "    embedding = dense_embeddings,\n",
        "    sparse_embedding = sparse_embeddings,\n",
        "    retrieval_mode = RetrievalMode.HYBRID,\n",
        "    vector_name = \"dense1\",\n",
        "    sparse_vector_name = \"sparse1\",\n",
        ")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {
        "id": "im0otLb5_aSK"
      },
      "outputs": [],
      "source": [
        "from uuid import uuid4\n",
        "uuids = [str(uuid4()) for _ in range(len(docs))]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "id": "ql0kwt7i_ONf"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "['df3ed049-d3a2-435d-aefd-097d1e90dff5',\n",
              " '8bcc0506-491a-462d-b5d3-c9cf867e6107',\n",
              " 'ee11554a-7a8b-4802-9646-9c707cccb315']"
            ]
          },
          "execution_count": 12,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "db.add_documents(documents=docs, ids=uuids)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {
        "id": "JZ6CzaV7-TqE"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "storage.sqlite\n"
          ]
        }
      ],
      "source": [
        "!ls /tmp/db/collection/agenticrag"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Jw9P4l7B4PXk"
      },
      "source": [
        "> Data is ingested, its time for the inference and building LangGraph nodes for Agentic RAG."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 14,
      "metadata": {
        "id": "L3SZyF6mXsVa"
      },
      "outputs": [],
      "source": [
        "query = \"module-2 content\"\n",
        "relevant_docs = db.similarity_search(query) # mmr: relevance + diversity"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 15,
      "metadata": {
        "id": "7QO4DQ3R_nJC"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "3"
            ]
          },
          "execution_count": 15,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "len(relevant_docs)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 19,
      "metadata": {
        "id": "X7sQKYL1ADxG"
      },
      "outputs": [],
      "source": [
        "retriever = db.as_retriever(search_type=\"mmr\",search_kwargs = {\"k\":3})"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 20,
      "metadata": {
        "id": "_V2Fj1odAFCY"
      },
      "outputs": [],
      "source": [
        "relevant_docs1 = retriever.invoke(query)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 21,
      "metadata": {
        "id": "gBb6pCyGALGb"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "{'producer': 'Microsoft® Word LTSC',\n",
              " 'creator': 'Microsoft® Word LTSC',\n",
              " 'creationdate': '2025-07-23T13:00:52+05:30',\n",
              " 'title': '',\n",
              " 'author': 'aDMIN',\n",
              " 'subject': '',\n",
              " 'keywords': '',\n",
              " 'moddate': '2025-07-23T13:00:52+05:30',\n",
              " 'source': 'data/23AI5PCOTM-OTML.pdf',\n",
              " 'total_pages': 3,\n",
              " 'page': 0,\n",
              " '_id': 'df3ed049-d3a2-435d-aefd-097d1e90dff5',\n",
              " '_collection_name': 'agenticrag'}"
            ]
          },
          "execution_count": 21,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "relevant_docs1[1].metadata"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "pb3kOywa_4cX"
      },
      "source": [
        "## Agentic Setup: Answer Generation (Implement Function calling router)\n",
        "\n",
        "Function calling lets you connect models to external tools and APIs. Instead of generating text responses, the model determines when to call specific functions and provides the necessary parameters to execute real-world actions. This allows the model to act as a bridge between natural language and real-world actions and data.\n",
        "\n",
        "> Image credits: [https://ai.google.dev/gemini-api/docs/function-calling](https://ai.google.dev/gemini-api/docs/function-calling)\n",
        "\n",
        "Our goal:\n",
        "- Have 2 tools: Knowledge base and Web Search tool\n",
        "- If query is from knowledge base, route to retrieve_docs tool\n",
        "- If query is not from knowledge base, route to web_search tool"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "jRJ2Ad-vXRxb"
      },
      "source": [
        "![image.png]()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "fT4is-_06o4N"
      },
      "source": [
        "> Fig.1: Function calling workflow"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Nh7qPDUe41oC"
      },
      "source": [
        "## Tool-1: Knowledge base retriever:\n",
        "\n",
        "Retrieve right document from the knowledge base."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 22,
      "metadata": {
        "id": "lbntm_u-cVQW"
      },
      "outputs": [],
      "source": [
        "def retrieve_docs(query:str) -> str:\n",
        "  \"\"\"\n",
        "  retrieve relevant document from the knowledge base. use retrieve_docs function to get the results\n",
        "\n",
        "  Args:\n",
        "      query: user prompt to retrieve the context\n",
        "  \"\"\"\n",
        "  response = retriever.invoke(query)\n",
        "  context = [docs.page_content for docs in response]\n",
        "\n",
        "  return \"\\n\".join(context)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "VXHZHkeo56bb"
      },
      "source": [
        "## Tool-2: Web Search\n",
        "\n",
        "Get information from DuckDuckGo Search using the pre-defined tool kit from Langchain"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 26,
      "metadata": {
        "id": "UNuAqSAdabHQ"
      },
      "outputs": [],
      "source": [
        "def web_search(query:str) -> str:\n",
        "    from langchain_community.tools import DuckDuckGoSearchRun\n",
        "\n",
        "    \"\"\"\n",
        "    search results from the Google web browswer to the user query\n",
        "    Args:\n",
        "       query: user prompt\n",
        "    \"\"\"\n",
        "    browse = DuckDuckGoSearchRun()\n",
        "    context = browse.invoke(query)\n",
        "    return context"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "V08v3G-d5BFX"
      },
      "source": [
        "## Execution: Execute the function tool logic\n",
        "\n",
        "Our goal is to let LLM chose what function is right for the given user query and then call that function along with the required arguments and then execute that code in the runtime using the interpreter: ``eval()`` function."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 25,
      "metadata": {
        "id": "J5KZcbflfuV5"
      },
      "outputs": [],
      "source": [
        "def extract_tool_call(text):\n",
        "    import io, re\n",
        "    from contextlib import redirect_stdout\n",
        "\n",
        "    pattern = r\"```tool_code\\s*(.*?)\\s*```\"\n",
        "    match = re.search(pattern, text, re.DOTALL)\n",
        "    if match:\n",
        "        code = match.group(1).strip()\n",
        "        f = io.StringIO()\n",
        "        with redirect_stdout(f):\n",
        "            result = eval(code)\n",
        "        output = f.getvalue()\n",
        "        r = result if output == '' else output\n",
        "        return f'```tool_output\\n{str(r).strip()}\\n```'''\n",
        "    return None"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "NY_rU1LbYtsR"
      },
      "source": [
        "### LangGraph Implementation"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9jmUu1d0mWrw"
      },
      "source": [
        "We will use the same two above tools: retrieve_docs and web_search tool along with the execution tool to get context. This function calling workflow we will replicate using LangGraph as demonstrated in the previous about image, Fig.1."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 27,
      "metadata": {
        "id": "hdNjknVTZ0KA"
      },
      "outputs": [],
      "source": [
        "import os\n",
        "from google.colab import userdata\n",
        "from google import genai\n",
        "\n",
        "from langgraph.graph import StateGraph, START, END\n",
        "from typing import TypedDict"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "GqZDqLkvekGK"
      },
      "source": [
        "## Get Credentials\n",
        "\n",
        "- Get your OPIK API Key: [OPIK- Trace and Monitor](https://www.comet.com/signup?utm_source=workshop&utm_medium=partner&utm_campaign=tarun)\n",
        "- Get your Gemini API Key: [Gemma-3-27b](https://aistudio.google.com/)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 28,
      "metadata": {
        "id": "y_qexniagX2U"
      },
      "outputs": [],
      "source": [
        "os.environ['GOOGLE_API_KEY'] = userdata.get('GOOGLE_API_KEY')\n",
        "os.environ['OPIK_API_KEY'] = userdata.get(\"OPIK_API_KEY\")\n",
        "os.environ['OPIK_WORKSPACE'] = \"tarun-r-jain\"\n",
        "os.environ['OPIK_PROJECT_NAME'] = \"local-agentic-rag\""
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 29,
      "metadata": {
        "id": "IcMIfuBYg0Sa"
      },
      "outputs": [],
      "source": [
        "llm_client = genai.Client()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 30,
      "metadata": {
        "id": "gFcQ-O6wflVv"
      },
      "outputs": [],
      "source": [
        "response = llm_client.models.generate_content(\n",
        "    model=\"gemma-3-27b-it\",\n",
        "    contents=\"what is the capital of Germany?\",\n",
        ")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 32,
      "metadata": {
        "id": "3jRxKXgJYvQC"
      },
      "outputs": [],
      "source": [
        "class AgentState(TypedDict):\n",
        "    query: str\n",
        "    context: str\n",
        "    tool_response: str\n",
        "    final_response: str"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "T0Ot6jl_64R3"
      },
      "source": [
        "## Node-1: Given the user query, pick right tool\n",
        "\n",
        "This is where we use the first LLM function call, where LLM decide for the given user task which is the right tool. We define the delimiters.\n",
        "1. Send user message with instructions and function definitons and first user message.\n",
        "2. Handle Model response when a tool/function is used using ```tool_code``` delimiters\n",
        "3. Execute local function and create tool output string using execute_tool_call, the result should have ``tool_output`` delimiters."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 34,
      "metadata": {
        "id": "1Cu-skGyaJ_p"
      },
      "outputs": [],
      "source": [
        "def generate_tool_call_node(state: AgentState):\n",
        "    query = state[\"query\"]\n",
        "\n",
        "    prompt = f'''\n",
        "    You are expert router Agent, given the User Question, you need to pick relevant tools from the available Python methods only.\n",
        "    At each turn, if you decide to invoke any of the function(s), it should be wrapped with ```tool_code```.\n",
        "    The python methods described below are imported and available, you can only use defined methods.\n",
        "    The generated code should be readable and efficient.\n",
        "    The response to a method will be wrapped in ```tool_output``` use it to call more tools or generate a helpful, friendly response.\n",
        "    When using a ```tool_call``` think step by step why and how it should be used.\n",
        "\n",
        "    The following Python methods are available:\n",
        "\n",
        "    ```python\n",
        "    def retrieve_docs(query:str) -> str:\n",
        "      \"\"\"\n",
        "      retrieve relevant document from the knowledge base. use retrieve_docs function to get the results\n",
        "      Args:\n",
        "          query: user prompt to retrieve the context\n",
        "      \"\"\"\n",
        "\n",
        "    def web_search(query:str) -> str:\n",
        "      \"\"\"\n",
        "      search results from the Google web browswer to the user query\n",
        "      Args:\n",
        "        query: user prompt\n",
        "      \"\"\"\n",
        "    ```\n",
        "    - retrieve_docs needs to be picked by default in case of confusion. Retrieve docs contains information on Tips and Tricks for Vibe coding\n",
        "    - web_search: needs to be used if web search and information needs to be retrieved\n",
        "    User: {query}\n",
        "    '''\n",
        "\n",
        "    tool_response = llm_client.models.generate_content(\n",
        "        model=\"gemma-3-27b-it\",\n",
        "        contents=prompt,\n",
        "    )\n",
        "    return {\"tool_response\": tool_response.text}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vwO10WKC7p44"
      },
      "source": [
        "## Node-2: Final Answer Generation\n",
        "\n",
        "Once you get the context from the function call, generate the final results"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 33,
      "metadata": {
        "id": "FBlm_SyYaPay"
      },
      "outputs": [],
      "source": [
        "def generate_final_answer_node(state: AgentState):\n",
        "    query = state[\"query\"]\n",
        "    tool_response = state[\"tool_response\"] # tool_code\n",
        "\n",
        "    context = extract_tool_call(tool_response) # context\n",
        "\n",
        "    final_prompt = f\"\"\"\n",
        "    Answer the user question from the given CONTEXT.\n",
        "    <context>\n",
        "    CONTEXT: {context}\n",
        "    </context>\n",
        "    <question>\n",
        "    User Question: {query}\n",
        "    </question>\n",
        "    \"\"\"\n",
        "    results = llm_client.models.generate_content(\n",
        "        model=\"gemma-3-27b-it\",\n",
        "        contents=final_prompt,\n",
        "    )\n",
        "    return {\"final_response\": results.text,\"context\": context}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "uUtu7CXM7w7I"
      },
      "source": [
        "### Build Graph workflow"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 35,
      "metadata": {
        "id": "YfBwpjzYaRsW"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "<langgraph.graph.state.StateGraph at 0x7d088d5b4740>"
            ]
          },
          "execution_count": 35,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "workflow = StateGraph(AgentState)\n",
        "workflow.add_node(\"generate_tool_call\", generate_tool_call_node)\n",
        "workflow.add_node(\"generate_final_answer\", generate_final_answer_node)\n",
        "\n",
        "workflow.add_edge(START, \"generate_tool_call\")\n",
        "workflow.add_edge(\"generate_tool_call\", \"generate_final_answer\")\n",
        "workflow.add_edge(\"generate_final_answer\", END)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 36,
      "metadata": {
        "id": "sTguz919dRkI"
      },
      "outputs": [],
      "source": [
        "graph = workflow.compile()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 37,
      "metadata": {
        "id": "nR-2K5XEdTYk"
      },
      "outputs": [
        {
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAANAAAAFNCAIAAAD+SXYKAAAQAElEQVR4nOydB1gURxvHZ6/ROyIgIMXee000tkSNiVhjV9DYE3ti7ybWaKJRY4zGEqJGY+/6xdhL7NgiYhex0OHgjrv93ruF44A9vBsX4h7vTx+e3ZnZ2dn3/jttp8hYliUIUlTICIIUISg4pEhBwSFFCgoOKVJQcEiRgoJDihSrFVzkmYQHN1NTEzWZKjZTnbfrRyaTaDWs1qhLiGEYQliGJVqjYFIZo8nUhdH55ThKNJla7hJDp5IhpIQhWpbkc2SM7yWR6C7M0x8Ft5bKGbkN4+wpC6riUL6WC7FGGCvrhzu2NTb6WqoyRctIiVzBKGwkoA9tZt5gEjmj1ZAcaRC9pnSqAs0xOcFkjDaTC8NmhTB2NJKhREay7iIBzRYUUncm0Z9pcyUpk2XlcqLO0EI8qgwtXOLgLC1fx7FBmxLEirAewR2JiIm6kgY/vE+QbYOP3Uv42hEx8/hu6vlDcS8fqUCd1Ro7N2xnJbKzEsGtnhQNmVO91u7V33cj1sXJ3S9vnEpS2DJh04OJ+BG94CJPJxzb+qpsTYePevsQ62X7ssfP7meEzfSzd7AlYkbcgktJUP0649HAb4IUdlJi7UTfSN73S+zAuUEKhYgfVsSCu3Yq4dTOV0PmlyHFiR9HR/WdEuDopiDiRELESVpyxvFtxU5twKeDvdfPeUREi1gFt3724+p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XEgqpjDyPKpTPO1A4jh0eoZDbLVnZd/4PXaMfXOoSOsnPt0LBV5UvW7/dR1/cuXtm3NQGm/6c2a3TVL1zobwVr+8n2tiJtcderAMwt3z3KOG1ptx7AaT4ceuvB4GVbdv0LUVEiFhflNZ9vdRKsX7eeRtS4pVaDStStRHxzmlw9rB1cJHdO/80pB6/6ZOSXs1f+hmvl52NozIjhdfLu0Tw8IE/E+GYPKeFKS/4eiGV8tjfz6f84PDlpq56FvmyhJ+I9wYW8ZyGjBTVz1MfmZo7o9FoEpNieb2gNaBQ8DfxJBKZq4sXEY64+GemvFTqDIWcZ8CLTKZwduIfl5D8KuXRlZfDFpUhokXEs7ZsHBWlK9nePHa/Et+cBqlU6u72309QFTYNj669rNVC3BNUxT2n4ZMBfra20ugLT0kx4O7px+5eioZtxT0oS/SrJ4XPCFKlqW6feEismlt/PZTJ2O7jRN8qt5KZ92tn3FepSfnG1tlLcufEQ4+Sis4j/Ij4sZ61RdZOj1amsgE1vBzd39GJDhS8fBwfezvB01fRbayVvEtWtXrSX1tib55LlttJS1Us4eAuvtGwxsTHJMX+G6fNZOu3davd3INYC1a4PtyWxY9ePlYxUsbWSeHq4+juJ6Zvji+i4xJjUzNSM4mW+IbYdhxuDcWoMVa7AuahiJhHN5UZSi1rNI4p11C2XEsG6hcZZLIPc5Gz/qD+An0w1nhRwqxrwZJMrnUJWd1qh/msmxUJlwTuYonuWp2HPrCDiySkmmOTjkJ2B747WP9ONImvMx7dUSbHZaoztAzhH7TI6te2NHYwEhmPaoxFk32tzpDGgtZfqPfXx5Adj0HmnEx1ZyzRKuykriWkIdWdFVa33FgecOsjpEjBzd2QIgUFhxQpKDikSEHBIUUKCg4pUlBwSJHyfwAAAP//BnXNugAAAAZJREFUAwB3uOy/ItJOHgAAAABJRU5ErkJggg==",
            "text/plain": [
              "<langgraph.graph.state.CompiledStateGraph object at 0x7d088d4379e0>"
            ]
          },
          "execution_count": 37,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "graph"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 38,
      "metadata": {
        "id": "VBZWeQ2YdUeH"
      },
      "outputs": [],
      "source": [
        "result = graph.invoke({\"query\": \"who is Messi?\"})"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 39,
      "metadata": {
        "id": "h6VMi8Ngdg_n"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Lionel Messi, full name Luis Lionel Andres Messi, is an Argentine professional soccer player widely regarded as one of the greatest of all time. He was born on June 24, 1987, in Rosario, Argentina, and displayed prodigious talent from a young age. He currently plays for Inter Miami and the Argentina national team. He has also played for FC Barcelona and Paris Saint-Germain.\n"
          ]
        }
      ],
      "source": [
        "print(result[\"final_response\"])"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 41,
      "metadata": {
        "id": "edNtN1bSdxpQ"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Okay, I understand. The user is asking a general knowledge question about Messi. Since this isn't related to Vibe coding specifically, I should use the `web_search` tool to find information about him.\n",
            "\n",
            "```tool_code\n",
            "web_search(query=\"who is Messi?\")\n",
            "```\n"
          ]
        }
      ],
      "source": [
        "print(result['tool_response']) # it used search"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 42,
      "metadata": {
        "id": "GHMy2GgUjFwV"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "```tool_output\n",
            "Lionel Andrés \" Leo \" Messi [note 1] (Spanish: [ljoˈnel anˈdɾes ˈmesi] ⓘ; born 24 June 1987) is an Argentine professional footballer who plays as a forward for and captains both Major League Soccer club Inter Miami and the Argentina national team. Lionel Messi is an Argentine-born football (soccer) player who has been named the world’s best men’s player of the year seven times (2009–12, 2015, 2019, and 2021). In 2022 he helped Argentina win the World Cup. Naturally left-footed, quick, and precise in control of the ball, Messi is known as a keen pass distributor and can readily thread his way through packed defenses. What was Lionel Messi ’s childhood like? Lionel Messi started playing football as a boy and was noticed by clubs on both sides of the Atlantic. When he was 13, his family relocated to Barcelona. He played for FC Barcelona’s under-14 team, quickly graduating through the higher-level teams until his informal debut at age 16 with FC Barcelona in a friendly match. What are Lionel Messi ’s achievements? Lionel Messi scored 73 goals during the 2011–12 season while playing for FC Barcelona, breaking a 39-year-old record for single-season goals in a major European football league. In 2014 Messi led Argentina to the World Cup final, which Argentina lost, but Messi won the Golden Ball award as the tournament’s best player. During the 2016 Copa América Centenario tournament, he netted his 55th international goal to break Gabriel Batistuta’s Argentine scoring record. He led Argentina’s national team to win the 2021 Copa América and the 2022 World Cup, when he again won the Golden Ball award. Lionel Messi (born June 24, 1987, Rosario, Argentina) Argentine-born football (soccer) player who received a record-setting eight Ballon d’Or awards as the world’s top male player (2009–12, 2015, 2019, 2021, and 2023). In 2022 he helped Argentina win the Fédération Internationale de Football Association (FIFA)’s World Cup. See full list on britannica.com Messi started playing football as a boy and in 1995 joined the youth team of Newell’s Old Boys (a Rosario-based top-division football club). Messi ’s phenomenal skills garnered the attention of prestigious clubs on both sides of the Atlantic. At age 13 Messi and his family relocated to Barcelona, and he began playing for FC Barcelona’s under-14 team. He scored 21 goals in 14 games for the junior team, and he quickly graduated through the higher-level teams until at age 16 he was given his informal debut with FC Barcelona in a friendly match. Britannica Quiz See full list on britannica.com In the 2004–05 season Messi , then 17, became the youngest official player and goal scorer in the Spanish La Liga (the country’s highest division of football). Though only 5 feet 7 inches (1.7 metres) tall and weighing 148 pounds (67 kg), he was strong, well-balanced, and versatile on the field. Naturally left-footed, quick, and precise in control of the ball, Messi was a keen pass distributor and could readily thread his way through packed defenses. In 2005 he was granted Spanish citizenship, an honour greeted with mixed feelings by the fiercely Catalan supporters of Barcelona. The next year Messi and Barcelona won the Champions League (the European club championship) title. Messi ’s play continued to rapidly improve over the years, and by 2008 he was one of the most dominant players in the world, finishing second to Manchester United’s Cristiano Ronaldo in the voting for the 2008 Ballon d’Or. In early 2009 Messi capped off a spectacular 2008–09 season by helping FC Barcelona capture the club’s first “treble” (winning three major European club titles in one season): the team won the La Liga championship, the Copa del Rey (Spain’s major domestic cup), and the Champions League title. He scored 38 goals in 51 matches during that season, and he bested Ronaldo in the balloting for both the Ballon d’Or and FIFA’s world player of the year by a record margin. During the 2009–10 season Messi scored 34 goals in domestic games as Barcelona repeated as La Liga champions. He earned the Golden Shoe award as Europe’s leading scorer, and he received another Ballon d’Or (the award was known as the FIFA Ballon d’Or in 2010–15). Messi led Barcelona to La Liga and Champions League titles the following season, which helped him capture an unprecedented third consecutive world player of the year award. In March 2012 he netted his 233rd goal for Barcelona, becoming the club’s all-time leading scorer in La Liga play when only 24 years old. He finished Barcelona’s 2011–12 season (which included another Copa del Rey win) with 73 goals in all competitions, breaking Gerd Müller’s 39-year-old record for single-season goals in a major European football league. His landmark season led to his being named the 2012 world player of the year, which made Messi the first player to win the honour four times. His 46 La Liga goals in 2012–13 led the league, and Barcelona captured another domestic top-division championship that season. In 2014 he set the overall Barcelona goal record when he scored his 370th goal as a member of the team. That same year he also broke the career scoring records for play in both the Champions League (with 72 goals) and La Liga (with 253 goals). Messi helped Barcelona capture another treble during the 2014–15 season, leading the team with 43 goals scored over the course of the campaign, which resulted in his fifth world player of the year honour. He scored 41 goals across all competitions for Barcelona in 2015–16, and the club won the La Liga title and the Copa del Rey during that season. Messi topped that with 53 goals for Barcelona in 2016–17, leading the team to another Copa del Rey title. In 2017–18 he scored 45 goals, and Barcelona won the La Liga–Copa del Rey double once again. Messi scored 51 goals across all domestic competitions in 2018–19 as Barcelona won another La Liga championship. In late 2019 he won his sixth career Ballon d’Or and was named FIFA’s best male player of the year. In the 2020–21 season, Barcelona claimed the Copa del Rey title, the seventh of Messi ’s career. He became a free agent in 2021, and financial issues—some of which were the result of La Liga rules—largely prevented him from re-signing with Barcelona. He left the club after setting a number of records; notably, he was the leading goal scorer in the league’s history (474). Special offer for students! Check out our special academic rate and excel this spring semester! Learn More See full list on britannica.com Despite his dual citizenship and professional success in Spain, Messi ’s ties with his homeland remained strong, and he was a key member of various Argentine national teams from 2005. He played on Argentina’s victorious 2005 FIFA World Youth Championship squad, represented the country in the 2006 World Cup, and scored two goals in five matches as Argentina swept to the gold medal at the Beijing 2008 Olympic Games. Messi helped Argentina reach the 2010 World Cup quarterfinals, where the team was eliminated by Germany for the second consecutive time in World Cup play. At the 2014 World Cup, Messi put on a dazzling display, scoring four goals and almost single-handedly propelling an offense-deficient Argentina team through the group stage and into the knockout rounds, where Argentina then advanced to the World Cup final for the first time in 24 years. Argentina lost that contest 1–0 to Germany, but Messi nevertheless won the Golden Ball award as the tournament’s best player. During the 2016 Copa América Centenario tournament, he netted his 55th international goal to break Gabriel Batistuta’s Argentine scoring record. After Argentina was defeated in the Copa final—the team’s third consecutive finals loss in a major tournament— Messi said that he was quitting the national team, but his short-lived “retirement” lasted less than two months before he announced his return to the Argentine team. At the 2018 World Cup, he helped an overmatched Argentine side reach the knockout stage, where they were eliminated by eventual champion France in their first match. After a third-place finish at the 2019 Copa América, Messi led Argentina to victory in the tournament two years later, and he received the Golden Ball award. His success continued at the 2022 World Cup. There he guided Argentina to the finals, where he scored two goals—and made a penalty kick during the shootout—to help defeat France. Messi won the World Cup’s Golden Ball, becoming the first male player to receive that award twice. In addition, his outstanding play in the tournament was instrumental in Messi winning his eighth Ballon d’Or in 2023. See full list on britannica.com Off the field, Messi was one of the biggest athletic stars in the world. In addition to earning a football salary that was frequently, with Ronaldo’s, one of the two largest athletes’ salaries in all professional sports, he was an extremely successful product pitchman, notably for the sportswear company Adidas. In 2013 Messi and his father ( who han... See full list on britannica.com Feb 20, 2024 · Lionel Messi is an Argentinian soccer player who has played for FC Barcelona, Paris Saint-Germain, and currently, the MLS club Inter Miami CF as well as the Argentina national team. Is Lionel Messi a legend? From his early struggles to a stellar career, he is a true legend of the sport. Who is Lionel Messi? Lionel Messi, full name Luis Lionel Andres Messi, is an Argentine professional soccer player widely regarded as one of the greatest of all time. Born on June 24, 1987, in Rosario, Argentina, Messi displayed prodigious talent from a young age. What club did Lionel Messi play for? Messi played for FC Barcelona for 17 seasons before joining Paris Saint-Germain in 2021 for two seasons. In July 2023, he joined the MLS club Inter Miami. FC Barcelona forward Lionel Messi celebrates after scoring in a January 2006 match. He played for the club for 17 seasons. At age 13, Messi signed with FC Barcelona. When did Lionel Messi become a professional soccer player? Lionel Messi's journey in professional soccer began at the tender age of 13 when he joined FC Barcelona's youth academy, La Masia, after the club agreed to cover his medical treatments for a growth hormone deficiency. Does Lionel Messi have a party in the United States? Lionel Messi is having himself a party in the United States . And that will continue after he signed a contract extension at Inter Miami this week, which will keep the 38-year-old at the MLS club until the end of 2028. Is Lionel Messi a time athlete of the year? BBC Sport. BBC. 30 October 2023. Retrieved 30 October 2023. ^ Summerscales, Robert (5 December 2023). \" Lionel Messi Becomes First Men's Soccer Player To Be Named TIME Athlete Of The Year \". Sport Illustrated. Retrieved 25 December 2023. ^ \"SIX goal contributions! Lionel Messi sets two more MLS records vs. RBNY\". Major League Soccer. 4 May 2024. What role does Messi play? A versatile forward, Messi often plays as a classic number 10. Tactically, Messi plays in a free attacking role ; a versatile player, he is capable of attacking on either wing or through the centre of the pitch. Apr 18, 2025 · Who is Lionel Messi? Lionel Messi, full name Luis Lionel Andres Messi, is an Argentine professional soccer player widely regarded as one of the greatest of all time. Born on June 24, 1987, in Rosario, Argentina, Messi displayed prodigious talent from a young age. Jul 30, 2025 · Read CNN’s Fast Facts about Lionel “Leo” Messi and learn about the soccer player who plays for Argentina’s national team and Major League Soccer (MLS) club Inter Miami. 2 days ago · Lionel Messi is having himself a party in the United States. And that will continue after he signed a contract extension at Inter Miami this week, which will keep the 38-year-old at the MLS club ... 3 days ago · Lionel Messi has signed a contract extension to extend his stay at Inter Miami through the end of the 2028 MLS season, the team announced Thursday. Apr 18, 2025 · Who is Lionel Messi? Lionel Messi, full name Luis Lionel Andres Messi, is an Argentine professional soccer player widely regarded as one of the greatest of all time. Born on June 24, 1987, in Rosario, Argentina, Messi displayed prodigious talent from a young age. 3 days ago · Lionel Messi has signed a contract extension to extend his stay at Inter Miami through the end of the 2028 MLS season, the team announced Thursday. 3 days ago · With Inter Miami set to open a new stadium and the 2026 World Cup approach, Messi’s impact on the field is only a small portion of the story.\n",
            "```\n"
          ]
        }
      ],
      "source": [
        "print(result['context'])"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "IU-tLc7Xgr-d"
      },
      "source": [
        "## Monitor"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "n_6z9hCF8JtQ"
      },
      "source": [
        "Log traces and spans, define and compute evaluation metrics, score LLM outputs, compare performance across app versions, and more.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 43,
      "metadata": {
        "id": "th2vlSHDdkxj"
      },
      "outputs": [],
      "source": [
        "from opik import track, opik_context"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 44,
      "metadata": {
        "id": "0zOIe8t_hfkA"
      },
      "outputs": [],
      "source": [
        "@track\n",
        "def get_response(query):\n",
        "  result = graph.invoke({\"query\":query})\n",
        "\n",
        "  opik_context.update_current_trace(\n",
        "      metadata={\n",
        "          \"tool_response\": result['tool_response']\n",
        "      }\n",
        "  )\n",
        "\n",
        "  return result['final_response']"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 45,
      "metadata": {
        "id": "yLshlJ9ght2F"
      },
      "outputs": [
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "OPIK: Started logging traces to the \"local-agentic-rag\" project at https://www.comet.com/opik/api/v1/session/redirect/projects/?trace_id=019a22ef-986d-723f-a438-7de883db61dc&path=aHR0cHM6Ly93d3cuY29tZXQuY29tL29waWsvYXBpLw==.\n"
          ]
        },
        {
          "data": {
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            },
            "text/plain": [
              "\"Lionel Messi is an Argentine professional footballer who plays as a forward for and captains both Major League Soccer club Inter Miami and the Argentina national team. He is the national team's all-time leading goalscorer and most-capped player, and has won eight Ballon d'Or awards, the most for any footballer. He was born on June 24, 1987. He also won a gold medal at the 2008 Summer Olympics and has won 45 team trophies.\""
            ]
          },
          "execution_count": 45,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "get_response(\"who is Lionel Messi?\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "wJXJJWSj78WY"
      },
      "source": [
        "You can use the above OPIK URL and access the dashboard that will track, trace and monitor the performance of the LLM calls."
      ]
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "name": "[Gemma_3]Function_Calling_Routing_and_Monitoring_using_Gemma_Google_Genai.ipynb",
      "toc_visible": true
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
